<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script>
            //遍历数组
            var arr = ["孙悟空","猪八戒","沙和尚","唐僧"];
             for(var i=0; i<arr.length; i++){
                 console.log(arr[i]);
             }
             //练习：创建一个函数，将perArr中满18岁的Person提取出来，
             //      然后封装到一个新的数组中并返回；
             
             //创建构造函数
             function Person(name, age){
                 this.name = name;
                 this.age = age;
             }
             //修改Person原型中的toString方法
             Person.prototype.toString = function(){
                 return "Person[name="+this.name+",age="+this.age+"]";
             }
             //创建若干对象
             per1 = new Person("孙悟空", 16);
             per2 = new Person("猪八戒", 19);
             per3 = new Person("唐僧", 22);
             per4 = new Person("沙和尚", 37);
             per5 = new Person("红孩儿", 9);
             per6 = new Person("蜘蛛精", 30);
             //将对象封装到数组中
             var perArr = [per1,per2,per3,per4,per5,per6];

             function newPerson(oldArr){
                 var newArr = [];
                 for(var i=0; i<oldArr.length; i++){
                     if(oldArr[i].age >= 18)
                        newArr.push(oldArr[i]);
                 }
                 return newArr;
             }
             var result1 = newPerson(perArr);
             console.log(perArr);
             console.log(result1);
        </script>
    </head>
    <body>
        

    </body>
</html>